package com.dr.cmdb.core.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author rui.duan
 * @version 1.0
 * @className FiledCheckEnum
 * @description 菜单枚举
 * @date 2021-03-29 11:39
 */
@Getter
@AllArgsConstructor
public enum FiledTypeEnum {

    //检查字段是否存在
    SHORT_STRING("short_string","短字符"),

    LONG_STRING("long_string","长字符"),

    NUMBER("number","整型"),

    FLOAT("float","浮点"),

    DATE("date","日期"),

    TIME("time","时间"),

    ARRAY("array","数组"),

    BOOL("bool","布尔"),

    ENUM("enum","枚举"),

    IP4("ip4","ip4"),

    IP6("ip6","ip6"),


    ;


    private String code;
    private String value;
    

    /**
     * 根据code获取值
     * @param code
     * @return
     */
    public static String getValueByCode(String code) {
        FiledTypeEnum[] values = FiledTypeEnum.values();
        for (FiledTypeEnum type : values) {
            if (type.code.equals(code)) {
                return type.value;
            }
        }
        return null;
    }

    public static List<String> getCodes() {
        List<String> codes = Lists.newArrayList();
        FiledTypeEnum[] values = FiledTypeEnum.values();
        for (FiledTypeEnum type : values) {
            codes.add(type.getCode());
        }
        return codes;
    }

    /**
     * 根据value获取code
     * @param value
     * @return
     */
    public static String getCodeByValue(String value) {
        FiledTypeEnum[] values = FiledTypeEnum.values();
        for (FiledTypeEnum type : values) {
            if (type.value.equalsIgnoreCase(value)) {
                return type.code;
            }
        }
        return null;
    }
}
